package com.qiaoanju.web.security.handler;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.security.authentication.AuthenticationServiceException;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.RememberMeServices;
import org.springframework.security.web.authentication.logout.SimpleUrlLogoutSuccessHandler;

import javax.annotation.Resource;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by eversec
 * on 2017/9/22.
 */
public class CustomLogoutSuccessHandler extends SimpleUrlLogoutSuccessHandler {

    public static Logger logger = LogManager.getLogger(CustomuthenticationFailureHandler.class.getName());

    @Resource(name = "rememberMeServices")
    private RememberMeServices rememberMeServices ;
    @Override
    public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {

        logger.info("自定义退出成功！"+authentication.getPrincipal());
        //解决退出登录不清楚Cookies的问题
        rememberMeServices.loginFail(request,response);
        super.onLogoutSuccess(request, response, authentication);

    }
}
